﻿CREATE OR REPLACE FUNCTION USER_TAB_INSERT_TRIGGER_FUNC()
RETURNS TRIGGER AS $$
BEGIN
    INSERT INTO USER_SHADOW VALUES (NEW.ID, TRUE, CURRENT_DATE);
    RETURN NULL;
END;
$$
LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION USER_TAB_DELETE_TRIGGER_FUNC()
RETURNS TRIGGER AS $$
BEGIN
    DELETE FROM USER_SHADOW WHERE ID = OLD.ID;
    RETURN NULL;
END;
$$
LANGUAGE plpgsql;

CREATE TRIGGER INSERT_USER_TAB_TRIGGER
    AFTER INSERT ON USER_TAB
    FOR EACH ROW EXECUTE PROCEDURE USER_TAB_INSERT_TRIGGER_FUNC();

CREATE TRIGGER DELETE_USER_TAB_TRIGGER
    AFTER DELETE ON USER_TAB
    FOR EACH ROW EXECUTE PROCEDURE USER_TAB_DELETE_TRIGGER_FUNC();
